package com.spring.client;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@EnableEurekaClient
@RestController
public class ClientApplication {

	
	//private static Logger log = LoggerFactory.getLogger(DemoController.class);
	
	
	public static void main(String[] args) {
		SpringApplication.run(ClientApplication.class, args);
	}
	@Value("${server.port}")
	private String port;

	@RequestMapping(value = "sayHi")
	public String sayHi(@RequestParam(value = "name",defaultValue = "zhangsan") String name){
		return "hello:"+name+"----------and port:"+port;
	}
	
	@RequestMapping(value = "/setCookies",method = RequestMethod.GET)
    public  String setCookies(HttpServletRequest request,HttpServletResponse response){
        //HttpServerletRequest 装请求信息类
        //HttpServerletRespionse 装相应信息的类
		Cookie cookie1= null;
		Cookie[] cookies = request.getCookies();
		if (cookies != null) {
			for (Cookie c : cookies) {
				if (c.getName().equals("sessionId")) {
					cookie1 = c;
					break;
				}
			}
		}
		System.err.println("**************************cookie***************");
		System.err.println("sessionId="+cookie1.getValue());
		
		//Cookie cookie=new Cookie("sessionId","123456789");
        //cookie.setPath("/aa");
        //cookie.setDomain("zzx.com");
        //cookie.setValue("111111111");
       
        //javax.ws.rs.core.Cookie cookie1 = new javax.ws.rs.core.Cookie("flag", "111", "/res", "www.zzx.com");
        //response.addCookie(cookie);
        return "获得cookies信息成功";
    }
}
